<?php

class Default_Model_Productitem extends Zend_Db_Table_Abstract
{
    protected $_name = 'productitem';
    
    public function getAllData(){
		$query = $this->select()
                        ->setIntegrityCheck(false)
                        ->from(array('i'=>$this->_name))
                        ->joinLeft(array('c'=>'productcat'),'i.catId =c.id', array('c.name as catName'))
                        ->order('i.catId asc')
                        ->order('i.id asc');                                                                                        
        return $this->fetchAll($query);
    }
    public function getDataById($id){       
        $query = $this->select()     
                        ->setIntegrityCheck(false)                   
                        ->from(array('i'=>$this->_name))
                        ->joinLeft(array('c'=>'productcat'),'i.catId =c.id', array('c.name as catName'))
                        ->where('i.display = 1')                        
                        ->where('i.id = ?',(int)$id)
                        ->order('i.ord asc');
        return $this->fetchRow($query);
    }              
    public function getDataByCat($id){        
        $query = $this->select()     
                        ->setIntegrityCheck(false)                   
                        ->from(array('i'=>$this->_name))
                        ->joinLeft(array('c'=>'productcat'),'i.catId =c.id', array('c.name as catName'))
                        ->where('catId = ?',(int)$id)
                        ->order('i.id asc');                                                
        return $this->fetchAll($query);
    }
    public function addData($data){        
        $data = array('name'    => $data['name'],
                    'ord'       => $data['ord'],                
                    'display'   => $data['display'],
                    'catId'       => $data['catId']);             
        $idAdd = $this->insert($data);        
        return $idAdd;
    }
    public function updateData($id = '',$data){        
        $data = array('name'    => $data['name'],
                    'ord'       => $data['ord'],  
                    'catId'       => $data['catId'],              
                    'display'   => $data['display']);
        return $this->update($data, 'id = '.(int)$id);
    }            
    public function deleteData($id){        
        $this->delete('id = '.(int)$id);
    }               
}